package org.pidan.basic.multiThread;

/**
 * {@code @description}: 等待线程结束join
 * {@code @author}: huangyuxin
 * {@code @date}: 2023-12-13
 */
public class DengDaiJieShu {

    public static int num = 0;

    public static class T1 extends Thread {

        public T1(String name) {
            super(name);
        }


        @Override
        public void run() {
            System.out.println(this.getName() + " start " + System.currentTimeMillis());

            for (int i = 0; i < 10; i++) {
                num++;
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println(this.getName() + " end " + System.currentTimeMillis());
        }
    }


    /**
     * 相差3秒左右，说明主线程等待t1完成之后才继续执行的
     */
    public static void main(String[] args) throws InterruptedException {
        T1 t1 = new T1("t1");
        t1.start();
        t1.join();
        System.out.println(System.currentTimeMillis() + "  == num:" + num);
    }

}
